package com.hulman.oms.service;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.RunLog;
import com.hulman.oms.dao.RunLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@Service
public class RunLogService
{
    @Autowired
    private RunLogDao runLogDao;

    public List<RunLog> findRunLogs(Map<String, Object> map)
    {
        return runLogDao.findRunLogs(map);
    }

    public Integer findRunLogsCount(Map<String, Object> map)
    {
        return runLogDao.findRunLogsCount(map);
    }

    public Result findRunLogsResult(Map<String, Object> map)
    {
        Integer page = (Integer) map.get("page");
        Integer limit = (Integer) map.get("limit");
        if (page != null && limit != null)
        {
            map.put("start", (page - 1) * limit);
            map.put("length", limit);
        }
        int count = runLogDao.findRunLogsCount(map);
        List<RunLog> data = runLogDao.findRunLogs(map);
        return new Result(data, count);
    }

    public RunLog findRunLogById(Integer id)
    {
        return runLogDao.findRunLogById(id);
    }

    public void saveRunLog(RunLog runLog)
    {
        if (runLog.getId() != null && runLog.getId() != 0)
        {
            runLogDao.updateRunLog(runLog);
        } else
        {
            runLogDao.insertRunLog(runLog);
        }
    }

    public void deleteRunLogById(Integer id)
    {
        runLogDao.deleteRunLogById(id);
    }

    public void deleteRunLogs(int[] ids)
    {
        runLogDao.deleteRunLogs(ids);
    }

    public RunLog findLatestRunLog()
    {
        return runLogDao.findLatestRunLog();
    }
}
